#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<unordered_map>
#include<functional>
using namespace std;


class Solution {
public:
    int countSymmetricIntegers(int low, int high) {
        int ans = 0;
        for (int i = low; i <= high; i++) {
            string s = to_string(i);
            if (s.size() % 2)continue;
            int m = s.size() / 2;
            int diff = 0;
            for (int j = 0; j < m; j++)
                diff += (s[j] - s[j + m]);
            if (diff == 0)ans++;
        }
        return ans;
    }
};

class Solution {
public:
    int minimumOperations(string num) {
        int n = num.size();
        function<int(string)>f = [&](string tail)->int {
            size_t i = num.rfind(tail[1]);
            if (i == -1 || i == 0)return n;
            i = num.rfind(tail[0], i - 1);
            if (i == -1)return n;
            return n - i - 2;
        };
        int ret1 = min(min(f("00"), f("25")), min(f("75"), f("50")));
        int ret2 = n - (num.find('0') != -1);
        return min(ret1, ret2);
    }
};

class Solution {
public:
    long long countInterestingSubarrays(vector<int>& nums, int m, int k) {
        long long ans = 0;
        int s = 0;
        unordered_map<int, int>hash;
        hash[0] = 1;
        for (auto x : nums) {
            s += (x % m == k);
            ans += hash[(s - k + m) % m];
            hash[s % m]++;
        }
        return ans;
    }
};